﻿@{
    ViewData["Title"] = "资源管理";
    var list = ViewBag.list as List<SystemRes>;
    var parentList = ViewBag.parent as List<SystemRes>;
    long parentId = ViewBag.parentId;
    int maxLevel = ViewBag.maxLevel;

}

<partial name="breadcrumb"/>

<div class="layui-fluid">

    <div class="layui-card">

        <div class="layui-card-body">
            <span class="layui-breadcrumb">
                <a href='@Url.Action("List")'>根目录</a>
                @foreach (var item in parentList)
                {
                    <a href='@Url.Action("List", new {parentId = @item.Id})'>@item.Name</a>
                }

            </span>
        </div>

        <div class="layui-card-header ">
            <button class="layui-btn layui-btn-normal" onclick="xadmin.open('添加资源', '@Url.Action("Edit", new {parentId = parentId})', 800, 600)">
                <i class="layui-icon layui-icon-add-circle-fine"></i>添加
            </button>
        </div>
        <div class="layui-card-body">

            <table class="layui-table">
                <thead>
                <tr>
                    <th>编号</th>
                    <th>名称</th>
                    <th>地址</th>
                    <th>允许的操作</th>
                    <th>菜单显示</th>
                    <th>排序号</th>
                    <th>状态</th>
                    <th>添加时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                @foreach (var item in list)
                {
                    <tr>
                        <td>@item.Id</td>
                        <td>
                            @if (parentList.Count < maxLevel - 1)
                            {
                                <a href='@Url.Action("List", new {parentId = @item.Id})'>@item.Name</a>
                            }
                            else
                            {
                                @:@item.Name
                            }
                        </td>
                        <td>@item.Url</td>
                        <td>@item.Operations</td>
                        <td>@item.GetType()</td>
                        <td>@item.OrderNum</td>
                        <td>@item.GetStatus()</td>
                        <td>@item.AddTime.ToString("yyyy-MM-dd HH:mm")</td>
                        <td class="td-manage">
                            <div class="layui-btn-group">
                                <button type="button" class="layui-btn" title="编辑" onclick="xadmin.open('编辑资源', '@Url.Action("edit", new {id = item.Id})', 800, 600)" href="javascript:;">
                                    编辑
                                </button>
                                <button type="button" class="layui-btn layui-btn-danger" onclick="del_res(@item.Id)">删除</button>
                            </div>

                        </td>
                    </tr>
                }
                </tbody>
            </table>
        </div>
    </div>
</div>


@section Scripts{
    <script>

        function del_res(id) {
            layer.confirm('确定要删除资源吗？',
                function() {
                    $.post("@Url.Action("del")",
                        { id: id },
                        function(ro) {
                            layer.msg(ro.msg,
                                { time: 500 },
                                function() {
                                    if (ro.success) {
                                        location.reload();
                                    }
                                });
                        });
                });
        }
    </script>
}